<template>
	<view class="container">
		<block v-for="(dp, index) in list">
			<vant-cell  :key="index" :title="dp" @click="onSwitch(index)">
				<vant-icon v-if="dp === curentdp" slot="right-icon" name="success" size="24" color="#2eb9e2d9"/>
			</vant-cell>
		</block>

		<vant-button class="btn-bottom" block color="#40a9ff" @click="createDP">创建科室</vant-button>
	</view>
</template>

<script>
	import API from '@/api/const.js'
	import request from '@/http/index.js'
	
	export default {
		onLoad(option) {
			this.curentdp = option.dp;
			uni.setNavigationBarTitle({
				title:"我的科室"
			});
			this.getDeptList();
		},
		data() {
			return {
				curentdp: '',
				list: ['内科', '外科', '骨科']
			}
		},
		methods: {
			getDeptList() {
				request('POST', API.POST_PERSON_DEPT_LIST)
				.then(data => {
					console.log('list:', data);
				})
			},
			onSwitch(index) {
				const dp = this.list[index];
				uni.showModal({
					title: '进入科室',
					content: dp,
					success() {
						uni.switchTab({
							url:`/pages/tabBar/home/home?dp=${dp}`
						})
					}
				})
			},
			
			createDP() {
				uni.navigateTo({
					url:'/pages/createDepartment/createDepartment'
				})
			}
		}
	}
</script>

<style lang="scss">
	.container {
		padding-top: 10rpx;
	}
</style>
